/**
 * 客户问卷地址功能
 */

function quest_init( tar, quests, text )
{
	if( empty( quests ) )
	{
		tar.empty();
		return;
	}

	var size = quests.length;

	if( size == 0 )
		return;

	tar.empty();
	for( var i = 0; i < size; i++ )
	{
		var nu = quests[ i ];

		if( text )
			quest_add_text( tar, nu.name, nu.url );
		else
			quest_add( tar, nu.name, nu.url );
	}
}

function quest_collect( tar )
{
	var quests = [];

	tar.find( "p[rel='QUEST_ITEM']" ).each( function()
	{
		var name = $( this ).find( "input[name='name']" ).val();
		var url = $( this ).find( "input[name='url']" ).val();

		quests.push( {
			name: name,
			url: url
		} );
	} );

	return quests;
}

function quest_add( tar, name, url )
{
	tar.find( "> :not(p)" ).remove();

	var h = "<p rel=\"QUEST_ITEM\" class=\"rect left\" style=\"margin:2px 0 2px 0;\">";
	h += "<label> 名称：</label>";
	h += "<input name=\"name\" size=\"20\" value=\"" + name + "\" />";
	h += "<label> 网址：</label>";
	h += "<input name=\"url\" size=\"50\" value=\"" + url + "\" />";
	h += "<a href=\"" + url + "\" target=\"_blank\">[ 打开 ]</a>";
	h += "<input type='button' class='btn_cancel' title='删除'/>";
	h += "</p>";

	tar.append( h );

	var self = tar.find( "p:last" );
	self.find( ".btn_cancel" ).click( function()
	{
		$( this ).parent().remove();
	} );
}

function quest_add_text( tar, name, url )
{
	var h = "<a class='rect' style='display:inline-block;margin:1px 0 1px;' target='_blank' href='" + url + "'>";
	h += "<b>" + name + "</b>：";
	h += "<span class='caption'>" + url + "</span>";
	h += "</a><br>";

	tar.append( h );
}
